package com.dtsz.m2.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegluarUtils {

    /**
     * 手机号码表单验证
     *
     * @param str
     * @return
     */
    public static boolean isMobile(String str) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String s2 = "^[1](([3|4|5|6|7|8|9][\\d])|([4][5,6,7,8,9])|([6][5,6])|([7][3,4,5,6,7,8])|([9][8,9]))[\\d]{8}$";// 验证手机号
        if (!StringUtils.isEmpty(str)) {
            p = Pattern.compile(s2);
            m = p.matcher(str);
            b = m.matches();
        }
        return b;
    }

    /**
     * 长度必须8到16位必须包含字母和数字
     *
     * @param str
     * @return
     */
    public static boolean isLetterDigit(String str) {
        String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$";
        return str.matches(regex);
    }

    public static boolean isLetter(String str) {
        String regex = "^[a-z0-9A-Z]+$";
        return str.matches(regex);
    }

    public static boolean isLetterNumber(String str) {
        Pattern p = Pattern.compile("(\\w)\\1{5,}");
        Matcher m = p.matcher(str);
        return m.find();
    }

    public static boolean isLetterNumberA(String str) {
        String regex = "([a-zA-Z])\\1{3,}";
        return str.matches(regex);
    }
}
